package com.sgb.net.util;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author: 杨畔
 * @date: 2021/2/19 15:27
 * @Description: 拦截器，添加头部信息，例如token之类的
 */
public class HeaderInterceptor implements Interceptor {
    /**
     * todo demo
     */
    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        //todo add header
        String token = "";
        //todo 获取token
        builder.addHeader("Authorization", "Bearer " + token)
                .addHeader("platform", "android")
                .addHeader("Content-Type", "application/x-www-form-urlencoded")
                .addHeader("type", "app-api-java");
        return chain.proceed(builder.build());
    }
}
